/*
 * Created: Author: Aléx Carvalho / Date: Apr 9, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-11 01:28:43 -0300 (Thu, 11 Jun 2015) $
 */
package test;

import com.cpm.ServiceLocator;
import com.cpm.entities.Folder;
import com.cpm.entities.Indicator;
import com.cpm.entities.StrategicPlan;
import com.cpm.entities.User;
import com.cpm.entities.id.IntegerId;
import com.cpm.entities.types.Family;
import com.cpm.entities.types.IndicatorDirectionType;
import com.cpm.entities.types.IndicatorModeType;
import com.cpm.entities.types.IndicatorPeriodicity;
import com.cpm.wrapper.Limit;
import com.cpm.wrapper.Password;
import com.cpm.wrapper.Performance;
import com.cpm.wrapper.Position;
import com.cpm.wrapper.Weight;
import java.io.IOException;
import java.time.LocalDate;
import java.time.Month;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/carga")
public class InsertCarga extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        LocalDate start = LocalDate.of(2015, Month.JANUARY, 1);
        LocalDate end = LocalDate.of(2015, Month.DECEMBER, 31);

        User user = ServiceLocator.getUserRepository().findById(new IntegerId(1));

        StrategicPlan strategicPlan = ServiceLocator.getStrategicPlanRepository().findById(new IntegerId(1));

        for (int i = 0; i < 100; i++) {
            Folder folder = new Folder(1, Family.STRATEGIC_PLAN, new Performance(1f), "Folder " + i, null, user, strategicPlan, new Position((short)i));

            ServiceLocator.getFolderRepository().persist(folder);

            for (int j = 1; j < 50; j++) {

                Indicator indicator = new Indicator(folder.getId(), Family.FOLDER, new Weight((short)1), "R$",
                        IndicatorDirectionType.DIRECT, IndicatorPeriodicity.MONTHTY, IndicatorModeType.AVERAGE,
                        user, strategicPlan, "Indicador " + j, null,
                        start, end, new Position((short)j), null);

                ServiceLocator.getIndicatorRepository().persist(indicator);
            }
        }

        resp.getWriter().print("Insert inicial realizado com sucesso!");
    }
}
